/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-30
 * Time: 20:49
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1=new Object();
        Object locker2=new Object();
        Thread t1=new Thread(()->{
            synchronized(locker1){
                try {
                    Thread.sleep(1000);//sleep()是为了让t2线程拿到另一把锁
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
            synchronized (locker2){
                System.out.println("hello t1");
            }
        });
        Thread t2=new Thread(()->{
            synchronized(locker2){

            }
            synchronized (locker1){
                System.out.println("hello t2");
            }
        });
        t1.start();

        t2.start();
    }
}
